#!/bin/bash
set -x
## set -e出错就抛出
set -e
imagename=ycr.yonyoucloud.com/base/java:8-jdk-alpine-yms-${version}-nodep
tarname=${version}-nodep

mkdir -p /data/ymsworkspace/dockertardone/nodep/${version}
tarfile=/data/ymsworkspace/dockertardone/nodep/${version}/$tarname.tar
bakfile=/data/ymsworkspace/dockertardone/nodep/bak/${version}/$tarname-${BUILD_TIMESTAMP}.tar
rawdir=/data/ymsworkspace/noextspace/${version}/

cp -rf /data/ymsworkspace/build/dockerfile $rawdir
## 下面这句是因为set -e失败时，build不会向下走，加上||true以后非结尾的判断中命令出错，异常不会抛出
docker rmi -f $imagename||true
docker build -f ${rawdir}dockerfile -t $imagename $rawdir

if [ -a "$tarfile" ]; then
echo backup $tarfile
mkdir -p $bakfile
mv $tarfile $bakfile
fi

docker save -o $tarfile $imagename